const mysql = require('mysql')

let pool = mysql.createPool({
  host: 'localhost',
  PORT: '3306',
  user: 'root',
  password: '123456',
  database: 'learndata'
});

let allSqlAction = (sql, value) => {
  return new Promise(
    (resolve, reject) => {
      pool.getConnection(function(err, connection) {
        if(err) {
          console.log(err)
          reject(err)
        }
        else {
          console.log('数据库连接成功')
          connection.query(sql, value, (err, row) => {
            if(err) reject(err)
            else resolve(row)
            connection.release()
          })
        }
      })
    }
  )
}

module.exports = {
  allSqlAction
}